package com.yi.student.daoImpl;

import java.util.List;

import org.konghao.basic.peresist.BaseDao;
import org.springframework.stereotype.Repository;

import com.yi.student.dao.IRewardAndPunishDao;
import com.yi.student.model.RewardAndPubnish;

@Repository("rewardAndPunish")
public class RewardAndPunishDaoImpl extends BaseDao<RewardAndPubnish> implements
		IRewardAndPunishDao {

	@Override
	public List<RewardAndPubnish> listPunishStudent() {
		String hql = "select rsp from RewardAndPunish rsp  where rsp.isReward = 0";
		List<RewardAndPubnish> list = this.list(hql);
		return list;
	}

	@Override
	public List<RewardAndPubnish> listRewardStudent() {
		String hql = "select rsp from RewardAndPunish rsp  where rsp.isReward = 1";
		List<RewardAndPubnish> list = this.list(hql);
		return list;
	}
	
	public List<RewardAndPubnish> listRewardByStuId(int id){
		String hql = "select rsp from RewardAndPubnish rsp left join fetch rsp.stu where rsp.stu.id = ? and rsp.isReward = 1" ;
		List<RewardAndPubnish> list = (List<RewardAndPubnish>) this.list(hql, id);
		return list ;
	}

	public List<RewardAndPubnish> listPublishByStuId(int id){
		String hql = "select rsp from RewardAndPubnish rsp left join fetch rsp.stu where rsp.stu.id = ? and rsp.isReward = 0" ;
		List<RewardAndPubnish> list = (List<RewardAndPubnish>) this.list(hql, id);
		return list ;
	}

	@Override
	public List<RewardAndPubnish> listPad(int year, String semeter) {
		String hsq ="select rsp from RewardAndPubnish rsp left join fetch rsp.stu where rsp.isReward = 1 " ;
		if(year != 0){
			hsq += " and rsp.year=" + year ;
		}
		if(semeter != null && !"".equals(semeter)){
			hsq += " and rsp.semester=" + semeter ;
		}
		return this.list(hsq);
	}

	@Override
	public List<RewardAndPubnish> listPap(int year, String semeter) {
		String hsq ="select rsp from RewardAndPubnish rsp left join fetch rsp.stu where rsp.isReward = 0 " ;
		if(year != 0){
			hsq += " and rsp.year=" + year ;
		}
		if(semeter != null && !"".equals(semeter)){
			hsq += " and rsp.semester=" + semeter ;
		}
		return this.list(hsq);
	}

	@Override
	public List<RewardAndPubnish> listRadAndRpd(String xh) {

		String hql =  "select rsp from RewardAndPunish rsp  where rsp.stu.xh = ?";
		
		return this.list(hql, xh);
	}
	

}
